
var globalScope={
  grid:new Ext.util.MixedCollection(),
  win:new Ext.util.MixedCollection(),
  form:new Ext.util.MixedCollection(),
  queryWin:new Ext.util.MixedCollection(),
  queryForm:new Ext.util.MixedCollection(),
  opt:new Ext.util.MixedCollection(),
  delRecs:new Ext.util.MixedCollection(),
  preid:'newId',
  getTableName:function(tableName){ 
      if(Ext.isEmpty(tableName)){
        tableName=jspVarHandler.c_out_model_tableName;
      }
      return tableName;
  },
  _add:function(tableName,addHandle){
      tableName=globalScope.getTableName(tableName);
	  if(typeof(addHandle)=="function"){
	    Ext.apply(globalScope.win.get(tableName),{'addHandle':addHandle});
	  }
   	  globalScope.form.get(tableName).getForm().reset();
	  globalScope.win.get(tableName).show();
	  globalScope.opt.add(tableName,'add');
  },
  _update:function(tableName,updtHandle){
      tableName=globalScope.getTableName(tableName);
	  var r=globalScope.grid.get(tableName).getSelectionModel().getSelected();
	  if(Ext.isEmpty(r)){
	    Ext.Msg.alert('WARNING',jspVarHandler.fmt_info_required_update_record);
	    return false;
	  }
	  if(typeof(updtHandle)=='function'){
	    Ext.apply(globalScope.win.get(tableName),{'updtHandle':updtHandle});
	  }
	  globalScope.form.get(tableName).getForm().loadRecord(r);
	  globalScope.win.get(tableName).show();
	  globalScope.opt.add(tableName,'updt');
  },
  _view:function(params){
	  if(Ext.isEmpty(params)) params={};
	  var tableName=globalScope.getTableName(params.tableName);
	  Ext.applyIf(params,{title:jspVarHandler.c_out_model_title,width:800,height:500})
	  var flag=globalScope._update(tableName);
	  if(flag==false) return;
	  globalScope.win.get(tableName).hide()
	  var form=globalScope.form.get(tableName);
	  Ext.quick.quickViewWin(form,'view_win',params);
  },
  _delete:function(tableName){
       tableName=globalScope.getTableName(tableName);
	   var recs=globalScope.grid.get(tableName).getSelectionModel().getSelections();
	   if(recs.length==0){
	     Ext.Msg.alert('WARNING',jspVarHandler.fmt_info_info_required_delete_records);
	     return;	
	   }
		Ext.Msg.confirm(jspVarHandler.fmt_label_info,jspVarHandler.fmt_info_confirm_delete,function(btn){
		   	 if(btn=='yes'){
		       var delRecs=globalScope.delRecs.get(tableName);
		       if(Ext.isEmpty(delRecs)){
		         delRecs=[];
		         globalScope.delRecs.add(tableName,delRecs);
		       }
		   	   for(var i=0;i<recs.length;i++){
		   	     var r=recs[i];
		   	     globalScope.grid.get(tableName).getStore().remove(r);
		   	     var isNewRecord=r.isNewRecord;
		   	     if(Ext.isEmpty(isNewRecord)){
		   	       delRecs.push(r);
		   	     }
		   	   }
		     }	
		});
  },
  _query:function(tableName,beforeQuery,afterQuery){
    tableName=globalScope.getTableName(tableName);
    if(typeof(beforeQuery)=='function'){
    	Ext.apply(globalScope.queryWin.get(tableName),{'beforeQuery':beforeQuery});
    }
    if(typeof(afterQuery)=='function'){
    	Ext.apply(globalScope.queryWin.get(tableName),{'afterQuery':afterQuery});
    }
    globalScope.queryWin.get(tableName).show();
    
  },
  _cancel:function(tableName){
    tableName=globalScope.getTableName(tableName);
	globalScope.grid.get(tableName).reloadData();
    globalScope.delRecs.add(tableName,[]);
  },
  _cascadeSave:function(mainTable,subTable,mainColumns,subColumns,form,rec){
    function cascadeOpt(){
      form.getForm().updateRecord(rec);
      globalScope._save(mainTable,'quick/quickJsonProcess.html',false,null,false);
      globalScope._save(subTable,'quick/quickJsonProcess.html',true,{REFID:rec.id},false);
      return true;
    }
    var opt=globalScope.opt.get(mainTable);
    var result=false;
    if(opt=='cascadeAdd'){
      if(typeof(i_cascadeAdd)=='function'){
        result=i_cascadeAdd(mainTable,subTable,mainColumns,subColumns,form,rec);
      }else{ 
      	if(typeof(i_cascadePresave)=='function'){
      	   var dealResult=i_cascadePresave(mainTable,subTable,mainColumns,subColumns,form,rec);
      	   if(!dealResult) return;
      	}
        result=cascadeOpt();
      }
    }else if(opt=='cascadeUpdt'){
      if(typeof(i_cascadeUpdate)=='function'){
        result=i_cascadeUpdate(mainTable,subTable,mainColumns,subColumns,form,rec);
      }else{ 
      	if(typeof(i_cascadePresave)=='function'){
      	   var dealResult=i_cascadePresave(mainTable,subTable,mainColumns,subColumns,form,rec);
      	   if(!dealResult) return;
      	}
        result=cascadeOpt();
      }
    }
    return result;
  },
  _simpleSave:function(param){
    globalScope._save(param.tableName,param.url,param.isAsynchronous,param.postData,param.checkEmpty,param.saveTableName,param._afterSave);
  },
  _save:function(tableName,url,isAsynchronous,postData,checkEmpty,saveTableName,_afterSave){
            Ext.get(document.body).mask(jspVarHandler.fmt_info_saveMsg);
            tableName=globalScope.getTableName(tableName);
            if(Ext.isEmpty(saveTableName)){
              saveTableName=tableName;
            }
            if(Ext.isEmpty(url)){
              url=g_rootPath+'quick/quickCookieJsonProcess.html';
            }else{
              url=g_rootPath+url;
            }
            if(Ext.isEmpty(isAsynchronous)){
              isAsynchronous=true;
            }
            if(Ext.isEmpty(checkEmpty)){
              checkEmpty=true;
            }
		    var span=Ext.get(tableName+"_columns").dom;
		    var qcolumns=Ext.decode(span.innerText);
            var gridColumns=[];
		    Ext.each(Ext.ux.clone(qcolumns),function(col){
		      if(col.gridDisplay){
		       gridColumns.push(col);
		      } 
		    });		    
		    var delRecs=globalScope.delRecs.get(tableName);
            if(Ext.isEmpty(delRecs)){
              delRecs=[];
              globalScope.delRecs.add(tableName,delRecs);
            }
            var m=globalScope.grid.get(tableName).getStore().getModifiedRecords();     
		    if(m.length==0&&delRecs.length==0){
		      Ext.get(document.body).unmask();
		      if(checkEmpty) Ext.Msg.alert(jspVarHandler.fmt_label_warn,jspVarHandler.fmt_info_no_save_data);	
		      return;
		    }
		    var updtArray=[],addArray=[];
		    Ext.each(m,function(item){
		        var data=Ext.apply(item.data,{'ID':item.id});
		        var isNewRecord=item.isNewRecord;
		        if(Ext.isEmpty(isNewRecord)){
			    	updtArray.push(data);//update record
		        }else{
			    	addArray.push(data);//add record
		        }
		    });
		    var delIdArray=[];
		    Ext.each(delRecs,function(item){
		      delIdArray.push(item.id);//delete record
		    });
		    postData=Ext.apply({ addData:Ext.encode(addArray),updtData:Ext.encode(updtArray),delId:Ext.encode(delIdArray),tableName:saveTableName},postData);
		    if(isAsynchronous){
				Ext.Ajax.request({
				   method:'POST',
				   url:url,
				   success: function(response){
						         Ext.get(document.body).unmask();
				                 if(typeof(_afterSave)=='function'){
				                    _afterSave(response,gridColumns);
				                 }else{   
					                 var resp=Ext.decode(response.responseText);
					                 if(resp.result=='success'){
							             Ext.quick.reformatGridTable(globalScope.grid.get(tableName),gridColumns,resp.idMap);
									     globalScope.delRecs.add(tableName,[]);
								         Ext.Msg.alert(jspVarHandler.fmt_label_info,jspVarHandler.fmt_info_save_success,function(){});
					                 }else{
					                 	Ext.Msg.alert(jspVarHandler.fmt_label_info,resp.errorInfo);
					                 }
						         }
						        },
				   failure: function(response){
				                 //alert(response.responseText)
						         Ext.get(document.body).unmask();
						         Ext.Msg.alert(jspVarHandler.fmt_label_info,jspVarHandler.fmt_info_save_error);
						      },
				   params:postData
				});
			}else{
			     var resp=Ext.ux.Sjax.request('POST',url,postData);
		         Ext.get(document.body).unmask();
	             resp=Ext.decode(resp);
	             Ext.quick.reformatGridTable(globalScope.grid.get(tableName),gridColumns,resp.idMap);
			     globalScope.delRecs.add(tableName,[]);
		         Ext.Msg.alert(jspVarHandler.fmt_label_info,jspVarHandler.fmt_info_save_success,function(){});
			}
  },
  _back:function(url,matrix){
      if(Ext.isEmpty(url)) url=jspVarHandler.c_url_quickBack;
      if(Ext.isEmpty(matrix)) matrix=[];
      matrix.push(["parentId",jspVarHandler.c_out_model_parentId]);
      matrix.push(["tableName",jspVarHandler.c_out_model_parentTable]);
	  var form=createForm(url,matrix);
	  form.submit();
  },
  _columns:function(tableName,successFunction){
      Ext.get(document.body).mask(jspVarHandler.fmt_info_loadMsg);
	  var processUrl=g_rootPath+"quick/quickColumnJson.html";
	  Ext.Ajax.request({
	    method:'POST',
	    url:processUrl,
	    success:function(response){
	      successFunction(response.responseText);
	      Ext.get(document.body).unmask();
	    },
	    failure:function(){
	      Ext.Msg.alert(jspVarHandler.fmt_label_error,jspVarHandler.fmt_info_load_error);
	      Ext.get(document.body).unmask();
	    },
	    params:{tableName:tableName}
	  });      
  },
  _model:function(params,successFunction,dealCookie){
            Ext.get(document.body).mask(jspVarHandler.fmt_info_loadMsg);
            var processUrl=g_rootPath+'quick/quickModel.html';
            if(dealCookie){
              processUrl=g_rootPath+'quick/quickModelMain.html';
            }
			Ext.Ajax.request({
			   method:'POST',
			   url: processUrl,
			   success: function(response){
			                  successFunction(response.responseText);
			                  Ext.get(document.body).unmask();
					        },
			   failure: function(){
					          Ext.Msg.alert(jspVarHandler.fmt_label_error,jspVarHandler.fmt_info_load_error);
			                  Ext.get(document.body).unmask();
					      },
			   params:params
			});  
  },
  _cascadeAdd:function(mainTable,subTable){
	  globalScope.opt.add(mainTable,'cascadeAdd');
	  globalScope._cascade(mainTable,subTable,{tableName:subTable,REFID:'-1'},null);  
  },
  _cascadeUpdate:function(mainTable,subTable,param){
	  var grid=globalScope.grid.get(mainTable);
	  var r=grid.getSelectionModel().getSelected();
	  if(Ext.isEmpty(r)){
	    Ext.Msg.alert('WARNING',jspVarHandler.fmt_info_required_update_record);
	    return; 
	  }
	  globalScope.opt.add(mainTable,'cascadeUpdt');
	  if(Ext.isEmpty(param)) param={tableName:subTable,REFID:r.id};
	  globalScope._cascade(mainTable,subTable,param,r);  
  },
  
  _cascade:function (mainTable,subTable,param,rec){
	  var htmlDiv=Ext.get("subTable_html").dom;
	  globalScope._model(param,function(responseText){
		   htmlDiv.innerHTML=responseText;
		   var span=Ext.get(mainTable+"_columns").dom;
		   var columns=Ext.decode(span.innerText);
		   var subSpan=Ext.get(subTable+"_columns").dom;
		   
		   var subColumns=Ext.decode(subSpan.innerText);
		   var subColumns2=Ext.ux.clone(subColumns);
		    var subForm = new Ext.quick.QuickForm({
		        id:subTable+'_form',
		        labelAlign: 'right',
		        title: jspVarHandler.c_out_model_title,
			    autoHeight:true,
		        frame:true,
		        url:'form.jsp',
		        baseTabIndex:2000
			    },subColumns,2);
		   globalScope.form.add(subTable,subForm);	

		    Ext.get('subWindow-win').dom.innerHTML="";
			var subWin = new Ext.Window({
			    layout:'fit',
			    el:'subWindow-win',
			    width:800,
			    autoHeight:true,
			    closeAction:'hide',
			    buttonAlign:'center',
			    items: [subForm],
			    buttons: [{
			        text:jspVarHandler.fmt_button_conf,
			        tabIndex:subForm.lastTabIndex,
			        handler:function(){
			          var r=null;
			          if(globalScope.opt.get(subTable)=='updt'){
				          r=subGrid.getSelectionModel().getSelected();
				          subForm.getForm().updateRecord(r);
			          }else if(globalScope.opt.get(subTable)=='add'){
						  var r=subForm.newRecord(Ext.quick.globalScope.preid);
						  var store=subGrid.getStore();
						  subGrid.stopEditing();
				    	  store.insert(0,r); 
				    	  subGrid.startEditing(0,0);
				    	  r.dirty=true;
				    	  r.modified=r.data;
				    	  if(store.modified.indexOf(r)==-1){
				    	    store.modified.push(r);	
				    	  }
			          }
			          subWin.hide();
			        }
			    },{
			        text:jspVarHandler.fmt_button_close,
			        tabIndex:subForm.lastTabIndex+1,
			        handler:function(){subWin.hide()}
			    }]
			});
		    subWin.render(document.body);
			globalScope.win.add(subTable,subWin);
			
		   var toolbar=new Ext.ux.toolbar('subToolbar',{});
		   var subGrid= new Ext.quick.QuickGrid(subTable, {
		     region:'center',
		     collapsible:true,
		     split:true,
		     stripeRows: true, 
		     tbar:toolbar,
		     enableDragDrop:false,
		     title:'grid',
		     clicksToEdit:1,
		     'remove':true,
		     'smConfig':{/*handleMouseDown:Ext.emptyFn*/}
		   },subColumns2);
		   globalScope.grid.add(subTable,subGrid);
		   
			    
		
		   var form = new Ext.quick.QuickForm({
		       region:"north",
		       collapsible:true,
		       split:true,
		       labelAlign: 'right',
		       title: "detail",
		       frame:true,
			    autoHeight:true
		    },columns,3);

		    
//		  Ext.get('subTable_win').dom.innerHTML="";
		  var cascadeWin= new Ext.Window({
		    id:'c_win',
//		    el:'subTable_win',
		    layout:'border',
		    title:'cascade',
		    width:1000,
		    height:g_height*1.2,
//		    closeAction:'hide',
		    buttonAlign:'center',
		    items: [form,subGrid],
		    buttons: [{
		        text:jspVarHandler.fmt_button_conf,
	            tabIndex:form.lastTabIndex,
		        handler:function(){
/*		          
		          globalScope._cascadeSave(mainTable,subTable,columns,subColumns,form,rec);
		          cascadeWin.hide();
*/	             
		          if(globalScope.opt.get(mainTable)=='cascadeUpdt'){
			          var result=globalScope._cascadeSave(mainTable,subTable,columns,subColumns,form,rec);
			          if(result) cascadeWin.close();
		          }
		          else if(globalScope.opt.get(mainTable)=='cascadeAdd'){
					  rec=globalScope.form.get(mainTable).newRecord(Ext.quick.globalScope.preid);
					  var store=globalScope.grid.get(mainTable).getStore();
					  globalScope.grid.get(mainTable).stopEditing();
			    	  store.insert(0,rec); 
			    	  globalScope.grid.get(mainTable).startEditing(0,0);
			    	  rec.dirty=true;
			    	  rec.modified=rec.data;
			    	  if(store.modified.indexOf(rec)==-1){
			    	    store.modified.push(rec);	
			    	  }
			          var result=globalScope._cascadeSave(mainTable,subTable,columns,subColumns,form,rec);
		              if(result||Ext.isEmpty(result)) cascadeWin.close();
		         }
	          }
		    },{
		        text:jspVarHandler.fmt_button_close,
	            tabIndex:form.lastTabIndex+1,
		        handler:function(){cascadeWin.close();}
		    }]
		});  
		   cascadeWin.render(document.body);  
		   cascadeWin.show();  
		   
		  if(Ext.isEmpty(rec)==false){
//		    Ext.ux.println(rec.data)
		    form.getForm().loadRecord(rec);
		  }		   
	  });
},  
  _ready:function(tableName,needToolbar,containDiv) {
    // create the grid
    if(Ext.isEmpty(containDiv)){
      containDiv="mainGrid";
    }
    tableName=globalScope.getTableName(tableName);
    var span=Ext.get(tableName+"_columns").dom;
    var columns=Ext.decode(span.innerText);
    var gridColumns=[];
    Ext.each(Ext.ux.clone(columns),function(col){
      if(col.gridDisplay){
       gridColumns.push(col);
      } 
    });

    var formColumns=[];
    formColumns=Ext.ux.clone(gridColumns);
    
    var queryColumns=[];
    Ext.each(Ext.ux.clone(columns),function(col){
      if(col.allowQuery){
       col.allowBlank=true;
       queryColumns.push(col);
      } 
    });
    var toolbar=null;
    if(Ext.isEmpty(needToolbar)||needToolbar){
      toolbar=new Ext.ux.toolbar('toolbar',{});
    }
    
    var grid= new Ext.quick.QuickGrid(tableName, {
      el:containDiv,
      stripeRows: true, // stripe alternate rows
      enableDragDrop:false,
      excelTitle:"<c:out value='${model.title}'/>", 
	  clicksToEdit:1,
	  autoScroll:true,
	  tbar:toolbar,
	  'remove':true,
	  'smConfig':{/*handleMouseDown:Ext.emptyFn*/}
    },gridColumns);
    grid.render();
    globalScope.grid.add(tableName,grid);
    

    var queryForm = new Ext.quick.QuickForm({
        labelAlign: 'right',
        frame:true,
	    autoHeight:true,
        url:'form.jsp'
	    },queryColumns,queryColumns.length>5?2:1);
	globalScope.queryForm.add(tableName,queryForm);
	    
    Ext.get('query-win').dom.innerHTML="";
	var queryWin = new Ext.Window({
	    el:'query-win',
	    layout:'fit',
	    width:queryColumns.length>5?800:400,
	    autoHeight:true,
        title: jspVarHandler.c_out_model_title+"--"+jspVarHandler.fmt_label_query,	    
	    closeAction:'hide',
	    buttonAlign:'center',
	    items: [queryForm],
	    buttons: [{
	        text:jspVarHandler.fmt_button_query,
	        tabIndex:queryForm.lastTabIndex,
	        handler:function(){
	           var htmlDiv=Ext.get("table_html").dom;
	           var postData=queryForm.getForm().getValues();
	           Ext.apply(queryWin,{'queryData':postData});
	            if(Ext.isEmpty(queryWin.beforeQuery)==false){
	                queryWin.beforeQuery(postData);
	            }	           
	           globalScope._model(postData,function(responseText){
				    htmlDiv.innerHTML=responseText;
				    var htmlTable=Ext.get(tableName);
				    globalScope.grid.get(tableName).reloadData(htmlTable);	
		            if(Ext.isEmpty(queryWin.afterQuery)==false){
		                queryWin.afterQuery(responseText);
		            } 		      
		       },true);	
//		      queryForm.getForm().el.dom.action="<c:url value='/quick/quickSimpleQueryProcess.html'/>";
//		      queryForm.getForm().el.dom.submit();
	          queryWin.hide();
	        }
	    },{
	        text:jspVarHandler.fmt_button_reset,
	        handler:function(){queryForm.getForm().reset()}
	    },{
	        text:jspVarHandler.fmt_button_cancel,
	        tabIndex:queryForm.lastTabIndex+1,
	        handler:function(){queryWin.hide()}
	    }]
	});
	
	Ext.apply(queryWin,{'afterQuery':function(responseText){//after queried,renew the page toolbar
			var after_query_span=Ext.get('g_pageSpan_info_'+tableName).dom;
			var after_query_param=Ext.decode(after_query_span.innerText)
			after_query_param=Ext.apply({spanName:'g_pageSpan_'+tableName},after_query_param);
		    globalScope._pageSpan(after_query_param);   		            
	}});
	
	
	
	globalScope.queryWin.add(tableName,queryWin);
	
    var form = new Ext.quick.QuickForm({
        id:tableName+'_form',
        labelAlign: 'right',
        frame:true,
        autoHeight:true,
        url:'form.jsp'
	    },formColumns,formColumns.length>5?2:1);
   globalScope.form.add(tableName,form);	    

    Ext.get('window-win').dom.innerHTML="";
	var win = new Ext.Window({
	    layout:'fit',
	    el:'window-win',
	    title: jspVarHandler.c_out_model_title,
	    width:formColumns.length>5?800:600,
	    autoScroll:true,
	    autoHeight:true,
	    closeAction:'hide',
	    buttonAlign:'center',
	    items: [form],
	    buttons: [{
	        text:jspVarHandler.fmt_button_conf,
	        tabIndex:form.lastTabIndex,
	        handler:function(){
	          var r=null;
	          if(globalScope.opt.get(tableName)=='updt'){
	              if(Ext.isEmpty(win.updtHandle)==false){
	                win.updtHandle(form);
       	            win.hide();
	                return;
	              }
		          r=grid.getSelectionModel().getSelected();
		          form.getForm().updateRecord(r);
	          }else if(globalScope.opt.get(tableName)=='add'){
	              if(Ext.isEmpty(win.addHandle)==false){
	                win.addHandle(form);
       	            win.hide();
	                return;
	              }
				  var r=form.newRecord(Ext.quick.globalScope.preid);
				  var store=grid.getStore();
				  grid.stopEditing();
		    	  store.insert(0,r); 
		    	  grid.startEditing(0,0);
		    	  r.dirty=true;
		    	  r.modified=r.data;
		    	  if(store.modified.indexOf(r)==-1){
		    	    store.modified.push(r);	
		    	  }
	          }
	          win.hide();
	        }
	    },{
	        text:jspVarHandler.fmt_button_close,
	        tabIndex:form.lastTabIndex+1,
	        handler:function(){win.hide()}
	    }]
	});
    win.render(document.body);
	globalScope.win.add(tableName,win);
    queryWin.render(document.body);
    return grid;
  },

_validForm:function(form){
		var valid = true;
	    form.getForm().items.each(function(f){
	        if(!f.isValid(true)){
	            valid = false;
	            f.focus();
	            Ext.Msg.alert("WARN",jspVarHandler.getValidInfo(f.fieldLabel));
	            return false;
	        }
	    });
	    return valid;
  },
  _pageSpan:function(param){
     var span=Ext.get(param.spanName);
     var pageNo=param.pageNo;
     var rowsOfPage=param.rowsOfPage;
     var rowCount=param.rowCount;
     var pageCount=param.pageCount;
     var condition=param.condition;
     var htmlDiv=param.htmlDiv;
     var tableName=globalScope.getTableName(param.tableName);
	 span.dom.innerHTML=""
	 var html=jspVarHandler.fmt_page_span_html;
	 var re=new RegExp("#","g");
	 html=html.replace(re,"\"");
    var t=new Ext.Template(html);
    t.compile();
	var param={tableName:tableName,pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:condition};
	t.append(span,param);	
  },
  _gotoPage:function(param,postData){
	     var spanName=param.spanName;
	     var pageNo=param.pageNo;
	     var rowsOfPage=parseInt(param.rowsOfPage);
	     var rowCount=parseInt(param.rowCount);
	     var pageCount=Math.floor((rowCount+rowsOfPage-1)/rowsOfPage);
	     var condition=param.condition;
	     var htmlDiv=param.htmlDiv;
	     var dealCookie=param.dealCookie;
	     if(Ext.isEmpty(dealCookie)){
	        dealCookie=false;
	     }
		if(Ext.isEmpty(htmlDiv)) htmlDiv=Ext.get("table_html").dom;
	     var tableName=globalScope.getTableName(param.tableName);
		if(rowsOfPage==0) return;
		if(pageNo>pageCount||pageNo<=0){
			return;
		}
		if(Ext.isEmpty(postData)){
		  postData={};
		}
		postData=Ext.apply(postData,{tableName:tableName,pageNo:pageNo,rowsOfPage:rowsOfPage,quickWhere:condition});
        var queryData=globalScope.queryWin.get(tableName).queryData;
        if(Ext.isEmpty(queryData)==false){
		  postData=Ext.apply(postData,queryData);
		}
		
		if(Ext.isEmpty(jspVarHandler.c_out_model_parentId)==false){
			postData=Ext.apply({REFID:jspVarHandler.c_out_model_parentId},postData);
		}
		
		htmlDiv.innerHTML="";
		globalScope._model(postData,function(responseText){
			   htmlDiv.innerHTML=responseText;
			   var htmlTable=Ext.get(tableName);
			   globalScope.grid.get(tableName).reloadData(htmlTable);		   
		},dealCookie);		
		globalScope._pageSpan({spanName:spanName, tableName:tableName,pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:condition})
		g_currentPage=pageNo;
  },
  _exportExcel:function(tableName,postData){
		if(Ext.isEmpty(postData)){
		  postData={};
		}
	    tableName=globalScope.getTableName(tableName);
		postData=Ext.applyIf(postData,{tableName:tableName});
        var queryData=globalScope.queryWin.get(tableName).queryData;
        if(Ext.isEmpty(queryData)==false){
		  postData=Ext.apply(postData,queryData);
		}
		if(Ext.isEmpty(jspVarHandler.c_out_model_parentId)==false){
			postData=Ext.apply({REFID:jspVarHandler.c_out_model_parentId},postData);
		}
		  var p, v,matrix=[];    
		  for(p in postData) {        
		    if(postData.hasOwnProperty(p)) {            
		      v = postData[p];            
		      matrix.push([p,v]);
		   }   
		 }
		 var form=createForm(g_rootPath+'quick/quickExcel.html',matrix); 
		 form.submit();		
  },
  _changeQuickCookie:function(fname,fvalue){
     var cookieForm=Ext.get('cookieForm').dom;
     cookieForm.all(fname).value=fvalue;
  },
    _excel:function(fileName,tableName){
         tableName=globalScope.getTableName(tableName);
         if(Ext.isEmpty(fileName)){
           fileName="export";
         }
         var grid=globalScope.grid.get(tableName);
        var vExportContent = grid.getExcelXml();
        if (Ext.isIE6 || Ext.isIE7 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) {
            var fd=Ext.get('frmDummy');
            if (!fd) {
                fd=Ext.DomHelper.append(Ext.getBody(),{tag:'form',method:'post',id:'frmDummy',action:g_rootPath+'export/excel.html', target:'_blank',name:'frmDummy',cls:'x-hidden',cn:[
                    {tag:'input',name:'exportContent',id:'exportContent',type:'hidden'},
                    {tag:'input',name:'fileName',id:'fileName',type:'hidden',value:fileName}
                ]},true);
            }
            fd.child('#exportContent').set({value:vExportContent});
            fd.dom.submit();
        } else {
            document.location = 'data:application/vnd.ms-excel;base64,'+Base64.encode(vExportContent);
        }
  }
}
